package com.yl.util;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.yl.util.Constants;

/**
 * 
 * 日志记录类
 * @author czx
 * 
 */
public class FileLog {
	// 日志文件名
	private static final String logFileName = "log.txt";


	/**
	 * 记录日志
	 * 
	 * @param info
	 */
	public synchronized static void log(String info) {
		
		String content = FileIOUtil.readTxtFile(Constants.SDCARD_PATH + Constants.PATH_LOG + logFileName);
		
		SimpleDateFormat   formatter   =   new   SimpleDateFormat   ("yyyy年MM月dd日   HH:mm:ss     ");     
		Date   curDate   =   new   Date(System.currentTimeMillis());//获取当前时间     
		String   str   =   formatter.format(curDate); 
		info = content + str + info + "\r\n";
		byte[] bytes = null;
		try {
			bytes = info.getBytes("UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		FileIOUtil.writeFile(Constants.SDCARD_PATH + Constants.PATH_LOG, logFileName, bytes, true);
	}
}
